using DiLu.Expansion.File.Operates.FTP.Configs;

namespace DiLu.Expansion.File.Operates.FTP;

/// <summary>
///     删除FTP文件
/// </summary>
public static class DeleteFtpFile
{
    /// <summary>
    ///     删除FTP文件
    /// </summary>
    /// <param name="config">删除FTP文件配置</param>
    public static async ValueTask DeleteAsync(this DeleteFtpFileConfig config)
    {
        if (!config.FtpClient.IsConnected) await config.FtpClient.AutoConnect();
        if (!await config.FtpClient.FileExists(config.FileFullPath)) return;
        await config.FtpClient.DeleteFile(config.FileFullPath);
        //不自动关闭客户端直接返回
        if (!config.AutoCloseFtpClient) return;
        await config.FtpClient.CloseFtpClientConnectAsync();
    }
}